//
//  JFViewController.m
//  JFAlertController
//
//  Created by ranjingfu on 01/20/2016.
//  Copyright (c) 2016 ranjingfu. All rights reserved.
//

#import "JFViewController.h"
#import "JFAlertController.h"

@interface JFViewController ()

@end

@implementation JFViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIButton  *showAlertView = [[UIButton alloc] initWithFrame:CGRectMake(20, 100, 200, 40)];
    [showAlertView setTitle:@"点击显示AlertView" forState:UIControlStateNormal];
    [showAlertView addTarget:self action:@selector(showAlertView:) forControlEvents:UIControlEventTouchUpInside];
    [showAlertView setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view addSubview:showAlertView];
    
    UIButton  *showAction = [[UIButton alloc] initWithFrame:CGRectMake(20, 160, 200, 40)];
    [showAction setTitle:@"点击显示ActionSheet" forState:UIControlStateNormal];
    [showAction addTarget:self action:@selector(showActionSheet:) forControlEvents:UIControlEventTouchUpInside];
    [showAction setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self.view addSubview:showAction];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(IBAction)showAlertView:(id)sender
{
    JFAlertAction  *cancelAction = [JFAlertAction actionWithTitle:@"取消"
                                                            style:JFAlertActionStyleCancel
                                                          handler:^(JFAlertAction *action) {
                                                              NSLog(@"您点击了取消");
                                                          }];
    JFAlertAction  *okAction = [JFAlertAction actionWithTitle:@"确定"
                                                        style:JFAlertActionStyleDefault
                                                      handler:^(JFAlertAction *action) {
                                                          NSLog(@"您点击了确定");
                                                      }];
    JFAlertController  *alert = [JFAlertController alertControllerWithTitle:@"这是一个Alert"
                                                                    message:nil
                                                               cancelAction:cancelAction
                                                               ensureAction:okAction];
    [alert showInViewController:self];
}


-(IBAction)showActionSheet:(id)sender
{
    
    JFAlertAction  *cancelAction = [JFAlertAction actionWithTitle:@"取消"
                                                            style:JFAlertActionStyleCancel
                                                          handler:^(JFAlertAction *action) {
                                                              NSLog(@"您点击了取消");
                                                          }];
    JFAlertAction  *deleteAction = [JFAlertAction actionWithTitle:@"删除"
                                                            style:JFAlertActionStyleDestructive
                                                          handler:^(JFAlertAction *action) {
                                                              NSLog(@"您点击了删除");
                                                          }];
    
    JFAlertAction  *okAction = [JFAlertAction actionWithTitle:@"确定"
                                                        style:JFAlertActionStyleDefault
                                                      handler:^(JFAlertAction *action) {
                                                          NSLog(@"您点击了确定");
                                                      }];
    JFAlertController  *alert = [JFAlertController alertControllerWithTitle:@"这是一个actionSheet"
                                                                    message:nil
                                                             preferredStyle:JFAlertControllerStyleActionSheet];
    [alert addActions:@[cancelAction,deleteAction,okAction]];
    [alert showInViewController:self];
    
}

@end
